package cn.tedu._06springaop.egaop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoggerAspect {
    @Pointcut("execution(public boolean cn.tedu._06springaop.egaop.CarImpl.*(..))")
    public void pointCut(){}
    @Around("pointCut()")
    public Object arroundMethod(ProceedingJoinPoint joinPoint){
        Boolean result = false;
        try {
            System.out.println("[环绕通知]"+"开始添加购物车");
            result = (Boolean) joinPoint.proceed();
            if (result) {
                System.out.println("[环绕通知]"+"添加购物车成功");
            }else {
                System.out.println("[环绕通知]"+"添加购物车失败");
            }
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }finally {
            System.out.println("[环绕通知]"+"操作完成");
        }
        return result;
    }
}
